package wonder;

import java.io.File;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;

import wonder.tools.Config2;
import wonder.tools.LoggerHelper;

/**
 * <p>SWResource class.</p>
 *
 * @author u211354
 * @version $Id: $
 */
public class SWConfigResource {
    private static final Logger logger = LoggerHelper.getLogger();
    private static final Config2 config = new Config2();

    /**
     * <p>loadResource</p>
     *
     * @param fileName a {@link java.lang.String} object.
     * @throws java.lang.Exception if any.
     */
    public static void loadResource(String fileName) throws Exception {
        getConfig().load(new File(fileName));
        logger.debug("SWResource loaded by file: {}", fileName);
    }

    /**
     * <p>loadResource</p>
     *
     * @param in a {@link java.io.InputStream} object.
     * @throws java.lang.Exception if any.
     */
    public static void loadResource(InputStream in) throws Exception {
        getConfig().load(in, Config2.JSON_TYPE);
        logger.debug("SWResource loaded by stream: {}", in);
    }

    /**
     * <p>
     * loadResource.
     * </p>
     *
     * @param in a {@link java.io.InputStream} object.
     * @param type a int.
     * @throws java.lang.Exception if any.
     */
    public static void loadResource(InputStream in, int type) throws Exception {
        getConfig().load(in, type);
        logger.debug("SWResource loaded by stream: {}", in);
    }

    /**
     * <p>
     * setResource.
     * </p>
     *
     * @param map a {@link java.util.Map} object.
     * @throws java.lang.Exception if any.
     */
    public static void setResource(Map<Object,Object> map) throws Exception {
        getConfig().load(map);
        logger.debug("SWResource loaded by map: {}", map);
    }

    /**
     * <p>getParamString</p>
     *
     * @param string a {@link java.lang.String} object.
     * @return a {@link java.lang.String} object.
     */
    public static String getParamString(String string) {
        return getConfig().getString(string);
    }

    /**
     * <p>
     * getParamObject.
     * </p>
     *
     * @param key a {@link java.lang.String} object.
     * @return a {@link java.lang.Object} object.
     */
    public static Object getParamObject(String key) {
        return getConfig().getEntry(key);
    }

    /**
     * <p>
     * getMap.
     * </p>
     *
     * @return a {@link java.util.Map} object.
     */
    public static Map<Object,Object> getMap() {
        return new HashMap<Object,Object>(getConfig());
    }

    /**
     * <p>Getter for the field <code>config</code>.</p>
     *
     * @return a {@link wonder.tools.Config2} object.
     */
    protected static Config2 getConfig() {
        return config;
    }
}
